package me.helllp.dake.generator.utils;

import com.squareup.javapoet.ArrayTypeName;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import org.springframework.boot.SpringApplication;

import javax.lang.model.element.Modifier;

public class GenMethodUtils {
    public static MethodSpec createMainMethod(String simpleClassName) {
        ParameterSpec loopParam = ParameterSpec.builder(ArrayTypeName.of(String.class), "args").build();

        MethodSpec main = MethodSpec.methodBuilder("main")
                // 方法的修饰符
                .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                // 方法的返回值类型
                .returns(void.class)
                // 方法的参数
                .addParameter(loopParam)
                // 方法body内容
                // $L 会替换为变量total的值
                .addStatement("$T.run($L.class, args)", SpringApplication.class, simpleClassName)
                .build();

        return main;
    }
}
